#!/usr/bin/env python

import sys
from pyjon import defs, jsparser, interpr, lexer

ctx = interpr.PyJS()

def main(args):
    if len(args)>1:
        ctx.load_(args[1])

    while True:
        has_errors = False
        try:
            input_ = raw_input(">>> ")
            n = jsparser.parse(input_, "(stdin)")
            dump = ctx.exec_(n)
            if dump != None: print dump

        except (EOFError, KeyboardInterrupt):
            print
            return 0

        except interpr.JSError, e:
            has_errors = True
            print e.__class__.__name__ + ": " + str(e.message) + ", line " + str(e.lineNumber)

        except jsparser.Error_, e:
            has_errors = True
            print str(e.message)

        except lexer.ParseError, e:
            has_errors = True
            print str(e.message)

        except Exception: raise

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))



